import { createRouter, createWebHistory } from 'vue-router'
import Login from '../components/Login.vue'
import StudentList from '../components/StudentList.vue'
import LoginSession from '@/components/LoginSession.vue'
import LoginJWT from '@/components/LoginJWT.vue'
import Profile from '@/components/Profile.vue'
import Nav from '@/views/Nav.vue'
const routes = [
  { path: '/', component: Nav },
  { path: '/students', component: StudentList },
  { path: '/profile', component: Profile },
]

const router = createRouter({
  history: createWebHistory(),
  routes,
})

router.beforeEach((to, from, next) => {
  if (to.path === '/students' && !localStorage.getItem('token')) {
    next('/')
  } else {
    next()
  }
})

export default router
